extends Node

@export var levelScenes: Array[PackedScene]
@export var currentLevelIndex = 0
const GAME_OVER_SCREEN = preload("res://UI/game_over_screen.tscn")

func change_level(levelIndex):
	# 如果超过关卡上限回到第一关
	if (levelIndex >= levelScenes.size()):
		transition_to_scene(GAME_OVER_SCREEN.resource_path)
		return
	currentLevelIndex = levelIndex
	# 切换到对应场景
	transition_to_scene(levelScenes[levelIndex].resource_path)

func transition_to_scene(scenePath):
	$"/root/ScreenTransitionManager".transition_to_scene(scenePath)

func to_menu():
	transition_to_scene("res://UI/main_menu.tscn")

func to_next_level():
	change_level(currentLevelIndex + 1)

func to_first_level():
	change_level(0)

func to_current_level():
	change_level(currentLevelIndex)
